﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using PluginInterface;

namespace ExplorerPlugin
{
    public partial class ExplorerPluginClass : MyListviewItem, IPlugin
    {
        public ExplorerPluginClass()
        {
            InitializeComponent();
        }

        #region IPlugin Members

        IPluginHost myPluginHost = null;
        string myPluginName = "Explorer";
        string myPluginAuthor = "Adriaan Dekker";
        string myPluginDescription = "My first working plugin: Explorer";
        string myPluginVersion = "1.0.2";


        public virtual void Navigate(string text)
        {
            Console.WriteLine("Navigating to: " + text);
            Path = text;
        }

        public virtual void NavigateDown()
        {
            Console.WriteLine("Navigating down");
            Console.WriteLine("Not implemented!");
        }

        public virtual void NavigateUp()
        {
            Console.WriteLine("Navigating up");
            Console.WriteLine("Not implemented!");
        }

        public virtual void NavigateBack()
        {
            Console.WriteLine("Navigating back");
            Console.WriteLine("Not implemented!");
        }

        public virtual void NavigateForward()
        {
            Console.WriteLine("Navigating forward");
            Console.WriteLine("Not implemented!");
        }

        public string Path
        {
            get
            {
                return null; //tvw_maps.SelectedNode.FullPath;
            }
            set
            {
                string[] dirnames = value.Split(new string[] { "\\" /*tvw_maps.PathSeparator*/ }, StringSplitOptions.RemoveEmptyEntries);
                TreeNode selectedNode = new TreeNode();// tvw_maps.Nodes[0];
                selectedNode.Expand();
                //tvw_maps.Nodes.Find(value.Substring(value.IndexOf(tvw_maps.PathSeparator), value.Length - value.IndexOf(tvw_maps.PathSeparator)), true);
                for (int i = 0; i < dirnames.Length; i++)
                {
                    Console.WriteLine(" > Trying to find this node: " + dirnames[i]);
                    bool found = false;
                    foreach (TreeNode t in selectedNode.Nodes)
                    {
                        Console.WriteLine("(i)  checking subnode:" + t.Text);
                        if (t.Text.ToUpper() == dirnames[i].ToUpper())
                        {
                            selectedNode = t;
                            found = true;
                            break;
                        }
                    }
                    if (found)
                        Console.Write("(i) Found it!\n(i) Selected Node now is: " + selectedNode.Text + "\n");
                    else
                        Console.WriteLine("(i) Not found!");
                    selectedNode.Expand();
                }
            }
        }

        public string Description
        {
            get
            {
                // TODO:  Add ctlMain.Description getter implementation
                return myPluginDescription;
            }
        }

        public string Author
        {
            get
            {
                // TODO:  Add ctlMain.Author getter implementation
                return myPluginAuthor;
            }
        }

        public IPluginHost Host
        {
            get
            {
                // TODO:  Add ctlMain.Host getter implementation
                return myPluginHost;
            }
            set
            {
                myPluginHost = value;
            }
        }

        public void Initialize()
        {
            // TODO:  Add ctlMain.Initialize implementation
        }

        /*
    public string Name
    {
        get
        {
            // TODO:  Add ctlMain.Name getter implementation
            return myPluginName;
        }
    }
    */
        public UserControl MainInterface
        {
            get
            {
                // TODO:  Add ctlMain.MainInterface getter implementation
                return this;
            }
        }

        public string Version
        {
            get
            {
                // TODO:  Add ctlMain.Version getter implementation
                return myPluginVersion;
            }
        }

        public string Name
        {
            get { return myPluginName; }
            set { return; }
        }

        #endregion

        public void Explorer_Load(object sender, EventArgs e)
        {
            //FileBrowser.GetDrives(ref tvw_maps, ref lvw_files, "PC");
            //MessageBox.Show("hi there");
        }

        private void tvw_maps_DoubleClick(object sender, EventArgs e)
        {
            //FileBrowser.GetDrives(ref tvw_maps, ref lvw_files, "PC");
        }
    }
}
